Skip to content

feat(select): allow HTML within options#31072

Merged
thetaPC merged 31 commits into
nextfrom
FW-7137
Apr 28, 2026
Merged

feat(select): allow HTML within options#31072
thetaPC merged 31 commits into
nextfrom
FW-7137

Conversation

@thetaPC
Copy link
Copy Markdown
Contributor

@thetaPC thetaPC commented Apr 9, 2026

Issue number: resolves #29890


What is the current behavior?

Select only allows plain text to be passed within it's options.

What is the new behavior?

ion-select-option

  • Added default slot support for custom HTML content (images, avatars, icons, etc.) when innerHTMLTemplatesEnabled is true
  • Added start and end named slots for content that appears in the overlay interface but not in the selected text
  • Added description prop for text rendered below the option label in the overlay

ion-select

  • Selected text renders HTML content from the default slot, excluding start/end slot content
  • aria-label derives plain text only from the default slot, ensuring screen readers don't read slotted or element content
  • Added CSS variables for styling media within the selected text (--select-text-media-width, --select-text-media-height, etc.)

Overlay interfaces (alert, action-sheet, select-popover, select-modal)

  • All four interfaces render rich content (start, end, description, HTML label) consistently via the shared renderOptionLabel utility
  • Public interfaces (ActionSheetButton, AlertInput, SelectPopoverOption, SelectModalOption) are unchanged — rich content fields are on internal extended interfaces (SelectActionSheetButton, SelectAlertInput, SelectOverlayOption)
  • Content is sanitized via sanitizeDOMString before DOM injection to prevent XSS

Utilities

  • Added select-option-render.tsx: shared render utility for option labels across all overlay components
  • Added getOptionContent: extracts and clones slot content from ion-select-option for overlays and selected text
  • Added getDefaultSlotPlainText — extracts plain text from the default slot, used for labels and aria

Tests

  • Added E2E tests for rich content rendering across all four interfaces (single and multiple selection)
  • Added tests for slot positioning (start/end placement verification)
  • Added tests for selected text content verification (excludes slotted content)

Does this introduce a breaking change?

  • Yes
  • No

No, developers will be able to continue using plain text for select options as usual.

Other information

Preview

@github-actions github-actions Bot added the package: core @ionic/core package label Apr 9, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview, Comment Apr 27, 2026 9:30pm

Request Review

// --------------------------------------------------

.action-sheet-button-label {
gap: 12px;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use the same value that ionic uses.

Comment thread core/src/components/alert/alert.tsx
Comment thread core/src/components/alert/alert.tsx
Comment thread core/src/components/select-modal/select-modal.tsx
Comment thread core/src/components/select-modal/select-modal.tsx
/**
* Text that is placed underneath the option text to provide additional details about the option.
*/
@Prop() description?: string;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description isn't being used here to display on the screen because ion-select-option isn't used to display the options, it's done through the respective interface. So description is passed to the interface.

Comment thread core/src/components/select-option/select-option.tsx Outdated
Comment thread core/src/components/select-popover/select-popover.tsx
Comment thread core/src/components/select-popover/select-popover.tsx
Comment thread core/src/components/select/test/rich-content-option/index.html
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ionic theme, when you open and close the modal from the icon it scrolls to the bottom of the view and also the focus indicator is cut off:

bug-with-select-multiple.mov

This does not happen for:

  • The single value modal example
  • The ios theme
  • The md theme
  • The overflowing or multiple basic select test on next
    • However, the focus indicator issue is there on the multiple example

Note: I didn't test if this exact test has the issue on next since this test is new.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not able to replicate either issues on Chrome and Firefox. What are the steps you took?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Chrome or Firefox (does not happen in Safari):

  1. Navigate to https://ionic-framework-git-fw-7137-ionic1.vercel.app/src/components/select/test/rich-content-option?ionic:theme=ionic
  2. Click in the middle of the Modal item under Multiple Value
  3. See that the modal opens with the scroll at the top
  4. Click on the select icon of the Modal item under Multiple Value
  5. See that the modal is scrolled to the bottom and the last item is focused
  6. Refer to my video for visual steps

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add screenshot tests for this? We need to check the visual rendering as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that I didn't create screenshots for this is because the content for the options are based on the project so they're not fixed. Would it be beneficial to create screenshots for something like that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should define some good default styles for the rich content. As with slotted elements in input, it should look good out of the box without requiring additional styling from developers. I think we need to do this and then capture screenshots of it: Input: slot test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkbox for the multiple value select modal looks different than the UX requirements - do we have a way for them to make this change?

Our implementation Figma requirements
Our implementation Figma requirements

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't part of the scope in my opinion. The ticket is meant to add HTML content to the options.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to provide the styling out of the box, but we do need to make sure it's possible to achieve on this PR.

Comment thread core/src/components/select-option/select-option.tsx Outdated
Comment thread core/src/components/select/select.tsx
Comment thread core/src/utils/select-option-render.tsx
Comment thread core/src/utils/select-option-render.tsx
Comment thread core/src/utils/select-option-render.tsx
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The avatar size in md theme is way too large. Can we decrease it here to match the other themes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not modify the width since we'll eventually add sizes to native avatar and we can adjust it at that point. Let me know if you would still prefer to make the change now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have good defaults for the UI when rich content is passed. See my comment here: #31072 (comment)

If we don't plan to adjust the styles now, we should create a follow-up ticket.

test('should not have visual regressions when not expanded', async ({ page, skip }) => {
await page.goto(`/src/components/item-sliding/test/shapes`, config);

// TODO(FW-7288): Remove skip once fix has been implemented
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently fixing the test so I don't expect this skip to be here long. I only added it so it's not a blocker.

@thetaPC thetaPC requested a review from brandyscarney April 27, 2026 21:51
Copy link
Copy Markdown
Member

@brandyscarney brandyscarney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of my feedback can be done in follow-up tickets so I am approving this. Great work! 💪

@thetaPC thetaPC merged commit e39449e into next Apr 28, 2026
49 checks passed
@thetaPC thetaPC deleted the FW-7137 branch April 28, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package package: vue @ionic/vue package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants